package me.zhengjie.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.domain.FlowConfig;
import me.zhengjie.service.OrganizerService;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author 18485
 */
@RestController
@RequiredArgsConstructor
@Api(tags = "工具:工作流")
@RequestMapping("/api/organizer")
public class OrganizerController {

    private final OrganizerService organizerService;
    @Log("编排器部署")
    @ApiOperation("编排器部署: 工具")
    @PostMapping("/addFlow")
    public ResponseEntity<Object> addFlow(@RequestBody Map<String,String> map) {
        organizerService.deploymentRun(map);
        return new ResponseEntity<>(HttpStatus.CREATED);
    }

    @Log("编排器返回")
    @ApiOperation("编排器返回: 工具")
    @PostMapping("/infoFlow")
    public ResponseEntity<Object> infoFlow(@RequestBody Map<String,String> map) {
        FlowConfig infoFlow = organizerService.infoFlow(map);
        return new ResponseEntity<>(infoFlow, HttpStatus.OK);
    }

    @Log("编排器修改")
    @ApiOperation("编排器修改: 工具")
    @PostMapping("/editFlow")
    public ResponseEntity<Object> updateFlow(@RequestBody Map<String,String> map) {
        organizerService.updateFlow(map);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
